#!/usr/bin/env python

import sys, datetime, logging

import config

if config.gui:
	import wx
	import gui

class Log:
	def __init__(self):
		self.messages = []
		
		try:
			self.log = open(sys.path[0] + "\\logs\\" + str(datetime.datetime.today().replace(microsecond = 0)) + ".log", "w")
		except IOError:
			self.log = False
			
			if config.gui:
				gui.wx.LogMessage("Unable to create log.")
			else:
				print "Unable to create log."

	def __del__(self):
		if self.log:
			self.log.close()
	
	def __ne__(self, message):
		if config.debugging:
			try:
				if self.log:
					self.log.write(message + "\n")
					self.log.flush()
			except IOError:
				if config.gui:
					gui.wx.LogMessage("Error writing to disk.")
				else:
					print "Error writing to disk."
			
			if config.gui:
				gui.wx.LogMessage(message)
			else:
				print message

log = Log()